package net.begincode.service;

import net.begincode.enums.StatusEnum;
import net.begincode.mapper.UserMapper;
import net.begincode.model.User;
import net.begincode.model.UserExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by saber on 2017/9/22.
 */
@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 根据邮箱查询用户
     *
     * @param mail
     * @return 不存在返回空 存在就返回此对象
     */
    public User getByMail(String mail) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andMailEqualTo(mail).andStatusEqualTo(Integer.parseInt(StatusEnum.NO_DEL_FLAG.getCode()));
        List<User> list = userMapper.selectByExample(userExample);
        return list.size() > 0 ? list.get(0) : null;
    }
}
